package com.mytx.common.utils;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Utils {
    public static boolean isPhoneNumber(String mobiles) {

        Pattern p = Pattern.compile("^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\\d{8}$");
        Matcher m = p.matcher(mobiles);
        return m.matches();
    }

    public static String genSalt() {

        Random random = new Random();
        int end3 = random.nextInt(99999);
        //如果不足三位前面补0
        String str = String.format("%05d", end3);
        return str;
    }

    /**
     * 保留两位小数，小数后面的只舍不入
     *
     * @param number
     * @return
     */
    public static Double moneyFormat(Object number) {
        if (number == null) {
            return 0.0;
        }
        DecimalFormat format = new DecimalFormat("###########0.00");
        format.setRoundingMode(RoundingMode.FLOOR);
        return Double.valueOf(format.format(number));
    }


}
